*! version 1.1  mh 15/4/98  arb 20/8/98program define uniquelocal options "BY(string) GENerate(string) Detail"local varlist "req ex min(1)"local if "opt"local in "opt"parse "`*'"tempvar uniq recnum count touselocal sort : sortedbymark `touse' `if' `in'qui gen `recnum' = _nsort `varlist'summ `touse', meanonlylocal N = _result(18)sort `varlist' `touse'qui by `varlist': gen byte `uniq' = (`touse' & _n==_N)qui summ `uniq'di in gr "Number of unique values of `varlist' is  " in ye _result(18)di in gr "Number of records is  "in ye "`N'"if "`detail'" != "" {	sort `by' `varlist' `touse'	qui by `by' `varlist' `touse': gen int `count' = _N if _n == 1	label var `count' "Records per `varlist'"	if "`by'" == "" {		summ `count' if `touse', d	}	else {		by `by': summ `count' if `touse', d	}}if "`by'" !="" {	if "`generate'"=="" {		cap drop _Unique		local generat _Unique	}	else {		confirm new var `generate'	}        drop `uniq'	sort `by' `varlist' `touse'	qui by `by' `varlist': gen byte `uniq' = (`touse' & _n==_N)	qui by `by': replace `uniq' = sum(`uniq')	qui by `by': gen `generate' = `uniq'[_N] if _n==1	di in blu "variable `generate' contains number of unique values of `varlist' by `by'"	list `by' `generate' if `generate'!=., noobs nodisplay}sort `sort' `recnum'end